fix: use field assignment for non-exhaustive Spec in benchmarks#552
Conversation
…e Spec in benchmarks Benchmarks are compiled as separate crates, so constructing a #[non_exhaustive] struct with struct literal syntax causes E0639. Use Default::default() with field assignment instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a compilation failure in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Greptile SummaryThis PR fixes a compilation error in
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["build_small_spec() / build_large_spec()"] --> B["Spec::default()"]
B --> C["spec.name = ..."]
C --> D["spec.bin = ..."]
D --> E["spec.cmd = cmd"]
E --> F["return spec"]
style B fill:#c8f7c5,stroke:#27ae60
style A fill:#f9f9f9,stroke:#999
Reviews (1): Last reviewed commit: "fix: use field assignment instead of str..." | Re-trigger Greptile |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a compilation error in the benchmarks by changing how a #[non_exhaustive] struct is instantiated. The fix is valid. I have added one suggestion to address code duplication that is present in the changes, which would improve the overall maintainability of the benchmark code.
| let mut spec = Spec::default(); | ||
| spec.name = "test".to_string(); | ||
| spec.bin = "test".to_string(); | ||
| spec.cmd = cmd; | ||
| spec |
There was a problem hiding this comment.
This pattern for creating a Spec instance is also used in the build_large_spec function (lines 87-91). To improve maintainability and reduce code duplication, you could extract this logic into a helper function. For example:
fn build_spec_with_cmd(name: &str, bin: &str, cmd: SpecCommand) -> Spec {
let mut spec = Spec::default();
spec.name = name.to_string();
spec.bin = bin.to_string();
spec.cmd = cmd;
spec
}This helper could then be called from both build_small_spec and build_large_spec.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #552 +/- ##
==========================================
- Coverage 77.94% 72.40% -5.54%
==========================================
Files 48 48
Lines 6682 6830 +148
Branches 6682 6830 +148
==========================================
- Hits 5208 4945 -263
- Misses 1114 1242 +128
- Partials 360 643 +283 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### 🚀 Features - **(cli)** render all doc-related fields in --help output by [@jdx](https://github.com/jdx) in [#554](#554) - **(cli)** support reading spec from stdin via --file - by [@jdx](https://github.com/jdx) in [#555](#555) ### 🐛 Bug Fixes - **(zsh)** remove trailing space from completions and add directory slash by [@jdx](https://github.com/jdx) in [#556](#556) - use field assignment for non-exhaustive Spec in benchmarks by [@jdx](https://github.com/jdx) in [#552](#552) ### 📦️ Dependency Updates - update apple-actions/import-codesign-certs digest to fe74d46 by [@renovate[bot]](https://github.com/renovate[bot]) in [#550](#550) - update codecov/codecov-action digest to 1af5884 by [@renovate[bot]](https://github.com/renovate[bot]) in [#551](#551) - lock file maintenance by [@renovate[bot]](https://github.com/renovate[bot]) in [#547](#547)
Summary
coverageCI job fails withE0639: cannot create non-exhaustive struct using struct expressioninlib/benches/parse.rs#[non_exhaustive]onSpecprevents struct literal constructionSpec::default()with field assignment instead of struct literal syntaxTest plan
cargo build --benchescompiles successfully🤖 Generated with Claude Code
Note
Low Risk
Low risk: changes are confined to benchmark setup code and only adjust
Specconstruction to compile with#[non_exhaustive]types.Overview
Fixes
lib/benches/parse.rsto stop usingSpec { ..Default::default() }struct literals (which fail for#[non_exhaustive]types when benches compile as a separate crate). Bench specs are now created withSpec::default()followed by explicit field assignment forname,bin, andcmd.Written by Cursor Bugbot for commit c3424dc. This will update automatically on new commits. Configure here.